//https://leetcode.cn/problems/minimum-number-of-arrows-to-burst-balloons/
package codeRandomThoughts.Test452用最少数量的箭引爆气球;

import java.util.Arrays;

public class Solution {
    public int findMinArrowShots(int[][] points) {
        //首先对points进行排序
        //Xend递增
        //相同时Xstart递增
        Arrays.sort(points, (p1, p2) -> {
            if (Integer.compare(p1[1], p2[1]) == 0) return Integer.compare(p1[0], p2[0]);
            return Integer.compare(p1[1], p2[1]);
        });

        int arrow = 0;
        long end = Long.MIN_VALUE;

        for (int[] point : points) {
            //如果point的开头大于之前气球的end
           if (Long.compare(point[0], end) > 0){
                //更新end
                end = point[1];
                arrow++;
            }
        }
        return arrow;
    }
}
